package controll;

import java.util.List;

import modell.Gestor;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;

public class GestorHibernate implements IGestorDAO {
	private Session sessao;

	@SuppressWarnings("unchecked")
	@Override
	public List<Gestor> listar() {
		Criteria lista = sessao.createCriteria(Gestor.class);
		return lista.list();
	}

	@Override
	public void excluir(Gestor gestor) {
		this.sessao.delete(gestor);
	}

	@Override
	public void salvar(Gestor gestor) {
		this.sessao.save(gestor);
	}

	@Override
	public void alterar(Gestor gestor) {
		this.sessao.update(gestor);

	}

	public Session getSessao() {
		return sessao;
	}

	public void setSessao(Session sessao) {
		this.sessao = sessao;
	}

	@Override
	public Gestor pesquisarLogin(String usuario, String senha) {
		String sql = " from Gestor c where c.Login = :usuario and c.Senha = :senha";
		Query consulta = sessao.createQuery(sql);
		consulta.setString("usuario",usuario);
		consulta.setString("senha", senha);
		return (Gestor) consulta.uniqueResult();
	}

}
